<?php

namespace app\admin\controller;

use app\admin\service\UserService;

class UserController extends CommonController
{
//    protected $middleware = [Check::class]; // 中间件
    //分页列表
    public function getUserPageList()
    {
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(UserService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getList();
        return $this->return_result($this->returnData);
    }

    //客户信息
    public function getUserDetail(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(UserService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getDetail();
        return $this->return_result($this->returnData);
    }

    //添加
    public function toAddUser(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(UserService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toAdd();
        return $this->return_result($this->returnData);
    }

    //更新
    public function toUpdateUser(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(UserService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toUpdate();
        return $this->return_result($this->returnData);
    }

    //更新
    public function toUpdateUserStatus(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(UserService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->updateStatus();
        return $this->return_result($this->returnData);
    }

    //删除
    public function toDelUser(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(UserService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toDel();
        return $this->return_result($this->returnData);
    }
}
